<template>
  <el-row class="page-product">
    <el-col :span="24">
      <crumbs :keyword="keyword" />
      <categroy :types="types" />
      <!-- :areas="areas" -->
      <list :plist="plist" />
    </el-col>
    <!-- <el-col :span="5">
      <amap
        v-if="point.length"
        :width="230"
        :height="290"
        :point="point"/>
    </el-col> -->
  </el-row>
</template>

<script>
import Crumbs from "@/components/products/crumbs.vue";
import Categroy from "@/components/products/categroy.vue";
import List from "@/components/products/list.vue";
//import Amap from '@/components/public/map.vue'
import { fetchTreeList } from "@/api/product";
import { simpleSearch } from "@/api/esproduct";
export default {
  components: {
    Crumbs,
    Categroy,
    List
    //Amap
  },
  data() {
    return {
      plist: [],
      types: [],
      //areas:[],
      keyword: ""
      //point:[]
    };
  },
  async asyncData(ctx) {
    let self = this;
    let params = {};
    let keyword = ctx.query.keyword;
    //let city = ctx.store.state.geo.position.city
    if (keyword == "") {
      params = {
        pageNum: 0,
        pageSize: 10
      };
    } else {
      params = {
        pageNum: 0,
        pageSize: 10,
        keyword: keyword
      };
    }
    let { status, data } = await simpleSearch(params);
    // let {status,data} = await ctx.$axios.get('es/esProduct/search/simple?pageNum=0&pageSize=10',{
    //   params:{
    //     keyword
    //     //city
    //   }
    // })
    let res = await fetchTreeList();
    let list = data.data.list;
    let total = data.data.total;
    if (status === 200 && total > 0) {
      return {
        plist: list
          .filter(item => item.pic.length)
          .map(item => {
            return {
              id: item.id,
              type: item.productCategoryName,
              img: item.pic.split(",")[0],
              name: item.name,
              comment: Math.floor(Math.random() * 10000),
              rate: Math.floor(Math.random() * 5), //Number(item.biz_ext.rating),
              price: Number(item.price),
              scene: "",
              tel: "",
              status: "可订明日",
              location: "",
              module: item.productCategoryName,
              attr: item.subTitle.split(",")
            };
          }),
        keyword,
        //areas: areas.filter(item=>item.type!=='').slice(0,5),
        types: res.data.filter(item => item.name).slice(0, 5)
        //point: (pois.find(item=>item.location).location||'').split(',')
      };
    }
  }
};
</script>

<style lang="scss">
@import "@/assets/css/products/index.scss";
</style>
